/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package j2metar.io;
import javax.microedition.io.file.*;
import javax.microedition.io.*;
import java.io.*;

/**
 *
 * @author anup.s
 */
public class File {
private String path;
public static final char separatorChar='/';
private long length=-1;
private long lastModified=-1;
private String name;
    public File(String path) {
        this.path = path;
    }
    public boolean isDirectory(){
        if(path.endsWith("/"))
            return true;
        else
            return false;
    }
    public long length() {
        if (length == -1) {
            FileConnection fc=null;
            try {
                fc = getFileConnection();
                length = fc.fileSize();
            } catch (IOException ioe) {
            }finally{
                try{
                    fc.close();
                }catch(Exception e){

                }
            }
        }
        return length;
    }
    public long lastModified() {
        FileConnection fc = null;
        if (lastModified == -1) {
            try {
                fc = getFileConnection();
                length = fc.fileSize();
            } catch (IOException ioe) {
            } finally {
                try {
                    fc.close();
                } catch (Exception ignored) {
                }
            }
        }
        return length;
    }
    public String getName() {
        if (name == null) {
            FileConnection fc = null;
            try {
                fc = getFileConnection();
                name = fc.getName();
            } catch (IOException ioe) {
            } finally {
                try {
                    fc.close();
                } catch (Exception ignored) {
                }
            }
        }
        return name;
    }
    public FileConnection getFileConnection() throws IOException 
    {
        return (FileConnection) Connector.open(path);
    }

}
